import Vue from 'vue';

// 注册router组件
import Router from 'vue-router';
Vue.use(Router);

//导入组件
//登录
import Login from '../components/user/Login.vue';
//忘记密码
import forget from '../components/forget/forget.vue';
//首页
import home from '../components/home/home.vue';
import index from '../components/home/index.vue';
//项目管理
import projectMa from '../components/otherpage/projectMa.vue';
//bug管理
import bugMa from '../components/otherpage/bugMa.vue';
//组织架构
import departmentMa from '../components/otherpage/departmentMa.vue';
//动态管理
import dynamicMe from '../components/otherpage/dynamicMe.vue';
//角色权限
import rolePe from '../components/otherpage/rolePe.vue';


//解决重复点击相同路由
const routerPush = Router.prototype.push;
Router.prototype.push = function push(location) {
  return routerPush.call(this, location).catch(error => error);
};

const router = new Router({
  routes: [
    {
      path: '/',
      redirect: '/Login'
    },
    {
      path: '/Login',
      name: 'Login',
      component: Login
    },
    {
      path: '/home',
      name: 'home',
      component: home,
      redirect: '/index',
      children: [{
        path: '/index',
        name: 'index',
        component: index
      },
      {
        path: '/projectMa',
        name: 'projectMa',
        component: projectMa
      },
      {
        path: '/bugMa',
        name: 'bugMa',
        component: bugMa
      },
      {
        path: '/departmentMa',
        name: 'departmentMa',
        component: departmentMa
      },
      {
        path: '/rolePe',
        name: 'rolePe',
        component: rolePe
      },
      {
        path: '/dynamicMe',
        name: 'dynamicMe',
        component: dynamicMe
      }]
    },
    {
      path: '/forget',
      name: 'forget',
      component: forget
    },
  ]
});
// //导航守卫
// //使用router.beforeEach注册一个全局前置守卫，判断用户是否登录
// router.beforeEach((to, from, next) => {
//   if (to.path === '/login') {
//     next();
//   } else {
//     let token = localStorage.getItem('Authorization');
//     if (token === 'null' || token === '') {
//       next('/login');
//     } else {
//       next();
//     }
//   }
// });

// let router = new Router({
//   routes,
//   mode: 'history',
//   // 全局配置激活路由的class类名，处与活跃（动态）就会用上这个类名
//   linkActiveClass: 'active'
// })


// // 设置路由守卫，在进页面之前，判断有token，才进入页面，否则返回登录页面
// if (storage.get("token")) {
//   store.commit("setToken", localStorage.getItem("token"));
// }
// router.beforeEach((to, from, next) => {
//   // 设置路由守卫，在进页面之前，判断有token，才进入页面
//       if (token) {
//           next('/')
//       } else {
//           // 没有token就调用后端接口，跳转地址
//           getAddress().then((res) => {
//             if (res.data.code === 200) {
//               location.href = res.data.data.redirectUri
//             }
//           })
//       }
// });

export default router;
